package de.idgard.android.addon.ui.services.impl;

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import de.idgard.android.addon.ui.services.WebIconService;
import de.idgard.android.addon.ui.services.ZircoToIDGardAPI;
import de.idgard.android.utils.Base64Encoder;

/**
 * 
 * @author pratik popat
 * 
 */
class WebIconServiceImpl implements WebIconService {

	ZircoToIDGardAPI api;

	public void setZircoToIDGardAPI(ZircoToIDGardAPI api) {
		this.api = api;
	}

	@Override
	public String getFaviconAsBase64() {
		Bitmap bmp = api.getContainersCurrentView().getFavicon();
		if (bmp == null) {
			return null;
		}
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
		String imageBase64String = Base64Encoder.encode(stream.toByteArray());
		return "data:image/x-icon;base64," + imageBase64String;
	}
	

}
